package com.hyacinth.repository.jpa;

import com.hyacinth.entity.ResourceRole;
import com.hyacinth.entity.Role;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Class Description: 資源角色數據持久層
 *
 * @Version v1.0 2017/4/22 21:06
 * @JDK version 1.8.0_51
 * @Author zfb
 */
@Repository
public interface ResourceRoleRepository extends BaseRepository<ResourceRole, Long>,
        PagingAndSortingRepository<ResourceRole, Long>, JpaSpecificationExecutor<ResourceRole> {

    /**
     * 根據资源编码查詢角色集合
     *
     * @param resCode 资源编码
     * @return 角色集合
     */
    @Query("from Role r WHERE r.dataFlag='0' AND r.code IN" +
            " (SELECT rr.roleCode FROM ResourceRole rr WHERE rr.resCode=?1)" +
            " order by r.createTime ASC")
    List<Role> findRolesByResCode(String resCode);
}
